#include "../mqserver/binding.hpp"
#include <gtest/gtest.h>

mmq::BindingManager::ptr bmp;

class BindingTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        bmp = std::make_shared<mmq::BindingManager>("./data/meta.db");
    }
    virtual void TearDown() override
    {
        // bmp->Clear();
    }
};

// TEST(binding_test, insert_test)
// {
//     bmp->Bind("exchange1", "queue1", "news.music.#", true);
//     bmp->Bind("exchange1", "queue2", "news.sport.#", true);
//     bmp->Bind("exchange1", "queue3", "news.movie.#", true);
//     bmp->Bind("exchange2", "queue1", "news.music.pop", true);
//     bmp->Bind("exchange2", "queue2", "news.sport.football", true);
//     bmp->Bind("exchange2", "queue3", "news.movie.America", true);
//     ASSERT_EQ(bmp->Size(), 6);  
// }

TEST(binding_test, recovery_test)
{
    ASSERT_EQ(bmp->Exists("exchange1", "queue1"), true);
    ASSERT_EQ(bmp->Exists("exchange1", "queue2"), true);
    ASSERT_EQ(bmp->Exists("exchange1", "queue3"), true);
    ASSERT_EQ(bmp->Exists("exchange2", "queue1"), true);
    ASSERT_EQ(bmp->Exists("exchange2", "queue2"), true);
    ASSERT_EQ(bmp->Exists("exchange2", "queue3"), true);
}

// TEST(binding_test, select_test)
// {
//     ASSERT_EQ(bmp->Exists("exchange1", "queue1"), true);
//     ASSERT_EQ(bmp->Exists("exchange1", "queue2"), true);
//     ASSERT_EQ(bmp->Exists("exchange2", "queue1"), true);
//     ASSERT_EQ(bmp->Exists("exchange2", "queue2"), true);
//     mmq::Binding::ptr bp = bmp->GetBinding("exchange1", "queue1");
//     ASSERT_NE(bp.get(), nullptr);
//     ASSERT_EQ(bp->_exchange_name, "exchange1");
//     ASSERT_EQ(bp->_msgqueue_name, "queue1");
//     ASSERT_EQ(bp->_binding_key, "news.music.#");
// }

// TEST(binding_test, select_Exchange_test)
// {
//     mmq::MsgQueueBindingMap mqbmap = bmp->GetExchangeBindings("exchange1");
//     ASSERT_EQ(mqbmap.size(), 3);
//     ASSERT_NE(mqbmap.find("queue1"), mqbmap.end());
//     ASSERT_NE(mqbmap.find("queue2"), mqbmap.end());
// }

// TEST(binding_test, remove_queue_test)
// {
//     bmp->RemoveMsgQueueBindings("queue1");
//     ASSERT_EQ(bmp->Exists("exchange1", "queue1"), false);
//     ASSERT_EQ(bmp->Exists("exchange2", "queue1"), false);
// }

// TEST(binding_test, remove_exchange_test)
// {
//     bmp->RemoveExchangeBindings("exchange1");
//     ASSERT_EQ(bmp->Size(), 2); 
//     ASSERT_EQ(bmp->Exists("exchange1", "queue1"), false);
//     ASSERT_EQ(bmp->Exists("exchange1", "queue2"), false);
//     ASSERT_EQ(bmp->Exists("exchange1", "queue3"), false);
// }

// TEST(binding_test, remove_test)
// {
//     ASSERT_EQ(bmp->Exists("exchange2", "queue2"), true);
//     bmp->UnBind("exchange2", "queue2");
//     ASSERT_EQ(bmp->Exists("exchange2", "queue2"), false);
//     ASSERT_EQ(bmp->Exists("exchange2", "queue3"), true);
// }

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new BindingTest);
    int ret = RUN_ALL_TESTS();

    return 0;
}

